﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;

namespace demoDeviceChannelSwitch.Controls
{
    public class customDeviceChannelPanel : DeviceChannelPanel
    {
        #region Protected methods
        protected override void AddParsedSubObject(object obj)
        {
            if (this.IsInEditMode())
            {
                this.WriteObjects(obj);
            }
            else
            {
                base.AddParsedSubObject(obj);
            }
        }
        #endregion

        #region Private methods
        private bool IsInEditMode()
        {
            return SPContext.Current != null &&
                SPContext.Current.FormContext != null &&
                (SPContext.Current.FormContext.FormMode == SPControlMode.Edit || SPContext.Current.FormContext.FormMode == SPControlMode.New);
        }

        private void WriteObjects(object obj)
        {
            Control control = obj as Control;
            if (control != null)
            {
                this.Controls.Add(control);
            }
        }
        #endregion

    }
}
